﻿/**
 * jQuery EasyUI 1.2.6
 * 
 * Licensed under the GPL terms To use it on other terms please contact us
 * 
 * Copyright(c) 2009-2012 stworthy [ stworthy@gmail.com ]
 * 
 */
(function($) {
	$.parser = {
		auto : true,
		onComplete : function(_1) {
		},
		plugins : [ "linkbutton", "menu", "menubutton", "splitbutton",
				"progressbar", "tree", "combobox", "combotree", "numberbox",
				"validatebox", "searchbox", "numberspinner", "timespinner",
				"calendar", "datebox", "datetimebox", "slider", "layout",
				"panel", "datagrid", "propertygrid", "treegrid", "tabs",
				"accordion", "window", "dialog" ],
		parse : function(context) {
			var aa = [];// 存放指定上下文里面的插件的数组
			for ( var i = 0; i < $.parser.plugins.length; i++) {
				var name = $.parser.plugins[i];
				var plugins = $(".easyui-" + name, context);// 如果context为null，会处理整个文档
				if (plugins.length) {
					if (plugins[name]) {// 如果存在r[plugin]，首先说明，r只是一个元素，而非数组，那么直接执行里面的plugin
						plugins[name]();
					} else {// 否则存放这些plugin数组
						aa.push({
							name : name,
							jq : plugins
						});
					}
				}
			}
			if (aa.length && window.easyloader) {
				var names = [];
				for ( var i = 0; i < aa.length; i++) {
					names.push(aa[i].name);
				}
				easyloader.load(names, function() {
					for ( var i = 0; i < aa.length; i++) {
						var name = aa[i].name;
						var jq = aa[i].jq;
						jq[name]();
					}
					$.parser.onComplete.call($.parser, context);
				});
			} else {
				$.parser.onComplete.call($.parser, context);
			}
		}
	};
	$(function() {
		if (!window.easyloader && $.parser.auto) {
			$.parser.parse();
		}
	});
})(jQuery);
